home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!gate.demon.co.uk
- From: Jason <tmr@cosine.demon.co.uk>
- Newsgroups: comp.sys.cbm
- Subject: Re: Scanning strings under BASIC, avoiding INPUT "?"
- Date: Wed, 27 Mar 96 22:58:59 GMT
- Organization: Cosine Systems
- Message-ID: <9603272258.AA0014u@cosine.demon.co.uk>
- References: <4jc9kt$h3p@news.rrz.uni-koeln.de>
- X-NNTP-Posting-Host: gate.demon.co.uk
- X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
- X-Mail2News-Path: relay-1.mail.demon.net!gate.demon.co.uk
-
- Joerg Bleimann (a2233495@rrz.Uni-Koeln.DE) wrote:
-
- : I have got a problem with COMMODORE BASIC 2.0: I started programming a
- : text adventure on the C 64 and do not know how to make the computer
- : recognize the latter part of a bipartite command string (for example
- : "TAKE BOTTLE"). How can I search the whole string for empties (" ") to
- : redefine the part right from the empty as a new string?
-
- You need to use the sexy little MID$ command. Eg:
-
- 10 A$="EAT GOLDFISH"
- 20 B$=MID$(A$,5,8)
- 30 PRINT B$
-
- Will put just the word GOLDFISH on your screen.
-
- The first number specifies where to start from in A$ and the second says
- how much to take. You can, therefore use it to scan one character at a
- time through the string using MID$(A$,T,1) with T as a counter to find the
- space and then fracture the two halves off thus:
-
- 10 INPUT A$ ;Get a command
- 20 T=1 ;Reset variable T to scan the string
- 30 L=LEN(A$) ;Get length of the command string
- 40 IFMID$(A$,T,1)=" "THEN70 ;Read character and compare with space
- 50 T=T+1 ;Add one to counter
- 60 IFT<=LTHEN40 ;See if counter has passed the end of the string
- 70 C$=MID$(A$,1,T-1) ;C$=COMMAND$ (Get, Go, Etc.)
- 80 O$=MID$(A$,T+1,L-T) ;O$=OBJECT$ (Banana, North, Etc.)
- 90 PRINTC$:PRINTO$ ;Show the result of this test
-
- Since this is an example there is no error trapping for things like
- incorrect inputs, shifted spaces or having more than two words a line but
- it should be easy to add that to it! Hioe that helps!!
-
- Jason =-)
-